﻿using AMatysiak.Controls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AMatysiak.Methods;

namespace AMatysiakTest
{
    [TestClass]
    public class ValueBoxTest
    {
        [TestMethod]
        public void testIntTextBox()
        {
            ValueBox<int> box = new ValueBox<int>();
            box.Text = "10";

            Assert.AreEqual(10, box.Value);
        }

        [TestMethod]
        public void testSetValue()
        {
            ValueBox<double> box = new ValueBox<double>();
            box.Value = 10.25;

            Assert.AreEqual("10,25", box.Text);
        }

        [TestMethod]
        public void testSetAndManipulateValue()
        {
            ValueBox<double> box = new ValueBox<double>();
            box.Value = 10.25;
            box.Value += 0.75;

            Assert.AreEqual("11", box.Text);
        }

        [TestMethod]
        public void testChangeMethodToString()
        {
            ValueBox<double> box = new ValueBox<double>();
            box.FormatMethodToStrHandler = delegate(double value) { return value.ToString("C2"); };
            box.Value = 11;

            Assert.AreEqual("11,00 zł", box.Text);
        }

        [TestMethod]
        public void testChangeMethodToObject()
        {
            ValueBox<double> box = new ValueBox<double>();
            box.FormatMethodToObjHandler = delegate(string value) { return value.ToDouble(); };
            box.Text = "11,00 zł";

            Assert.AreEqual(11, box.Value);
        }
    }
}
